home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Games / Game Sample Code / ZAM 1.0a13 / UtilCode / DialogUtil.c < prev    next >
Encoding:
Text File  |  1993-09-16  |  2.5 KB  |  138 lines  |  [TEXT/KAHL]

  1.  
  2. /*
  3.     DialogUtil.c
  4.     ------------
  5.     
  6.     This is real old code I have been using since the start for dealing with the DialogManager
  7. */
  8.  
  9. PutNumericItem(DialogPtr theDialog, int itemNumber, int number)
  10. {
  11.     Handle    iHandle;
  12.     Rect    box;
  13.     int        iType;
  14.     Str255    tempString;
  15.     long    itemValue;
  16.     
  17.     NumToString(number,&tempString);
  18.     GetDItem(theDialog,itemNumber,&iType,&iHandle,&box);
  19.     SetIText(iHandle,&tempString);
  20. }
  21.  
  22. short GetNumericItem(DialogPtr theDialog, int itemNumber)
  23.  
  24. {
  25.     Handle    iHandle;
  26.     Rect    box;
  27.     int        iType;
  28.     Str255    tempString;
  29.     long    itemValue;
  30.     
  31.     GetDItem(theDialog,itemNumber,&iType,&iHandle,&box);
  32.     GetIText(iHandle,&tempString);
  33.     StringToNum(&tempString,&itemValue);
  34.     return(itemValue);
  35. }
  36.  
  37. GetTextItem(DialogPtr theDialog, int itemNumber, Str255 *text)
  38. {
  39.     Handle    iHandle;
  40.     Rect    box;
  41.     int        iType;
  42.     
  43.     GetDItem(theDialog,itemNumber,&iType,&iHandle,&box);
  44.     GetIText(iHandle,text);
  45. }
  46.  
  47. PutTextItem(DialogPtr theDialog, int itemNumber, Str255 *text)
  48. {
  49.     Handle    iHandle;
  50.     Rect    box;
  51.     int        iType;
  52.     
  53.     GetDItem(theDialog,itemNumber,&iType,&iHandle,&box);
  54.     SetIText(iHandle,text);
  55. }
  56.  
  57. ShowDialog(int dialog_id)
  58. {
  59.     DialogPtr    dialog_ptr;
  60.     int            itemHit;
  61.     
  62.     dialog_ptr = GetNewDialog(dialog_id,nil,(WindowPtr)-1);
  63.     ModalDialog(nil,&itemHit);
  64.     DisposDialog(dialog_ptr);
  65. }
  66.  
  67. int GetDialogCtlValue(DialogPtr dialog, int item)
  68. {
  69.     ControlHandle        iHandle;
  70.     Rect                box;
  71.     int                    iType;
  72.  
  73.     GetDItem(dialog,item,&iType,&iHandle,&box);
  74.     return(GetCtlValue(iHandle));
  75. }
  76.  
  77. SetDialogCtlValue(DialogPtr dialog, int item, int newValue)
  78. {
  79.     ControlHandle        iHandle;
  80.     Rect                box;
  81.     int                    iType;
  82.  
  83.     GetDItem(dialog,item,&iType,&iHandle,&box);
  84.     SetCtlValue(iHandle,newValue);
  85. }
  86.  
  87.  
  88. void BoxItem(DialogPtr dialog, int item)
  89. {
  90.     Handle        iHandle;
  91.     Rect        box;
  92.     int            iType;
  93.     GrafPtr        savePort;
  94.     
  95.     GetPort(&savePort);
  96.     SetPort(dialog);
  97.     GetDItem(dialog,item,&iType,&iHandle,&box);
  98.     InsetRect(&box,-2,-2);
  99.     FrameRect(&box);
  100.     SetPort(savePort);
  101. }
  102.  
  103. HilightItem(DialogPtr dialog, int item)
  104. {
  105.     Handle        iHandle;
  106.     Rect        box;
  107.     int            iType;
  108.     PenState    savePen;
  109.     GrafPtr        savePort;
  110.     
  111.     GetPort(&savePort);
  112.     SetPort(dialog);
  113.     GetPenState(&savePen);
  114.     GetDItem(dialog,item,&iType,&iHandle,&box);
  115.     PenSize(3,3);
  116.     InsetRect(&box,-4,-4);
  117.     FrameRoundRect(&box,16,16);
  118.     SetPenState(&savePen);
  119.     SetPort(savePort);
  120. }
  121.  
  122. int TrackDialogControl(DialogPtr dialog, int item, Point start)
  123. {
  124.     Handle        cHandle;
  125.     Rect        box;
  126.     int            iType;
  127.  
  128.     GetDItem(dialog,item,&iType,&cHandle,&box);
  129.     return(TrackControl(cHandle,start,nil));
  130. }
  131.  
  132. GetDbox(DialogPtr dialog, int item, Rect *box)
  133. {
  134.     Handle        iHandle;
  135.     int            iType;
  136.  
  137.     GetDItem(dialog,item,&iType,&iHandle,box);
  138. }